package huanzhao.erp.domain.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import huanzhao.erp.domain.types.TaskState;
import huanzhao.erp.domain.types.TaskType;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serial;
import java.io.Serializable;
import java.util.Date;

@TableName(value = "task")
@Data
@NoArgsConstructor
public class Task implements Serializable {

    @TableId(value = "id", type = IdType.AUTO)
    private Long id;

    /**
     * 手机id
     */
    @TableField(value = "phone_id")
    private Long phoneId;

    /**
     * 领取者id
     */
    @TableField(value = "receiver_id")
    private Long receiverId;

    /**
     * 任务所属团队id
     */
    @TableField(value = "team_id")
    private Long teamId;

    /**
     * 上一个任务id
     */
    @TableField(value = "last_task_id")
    private Long lastTaskId;

    /**
     * 任务时限，单位：秒，为空时表示没有时限
     */
    @TableField(value = "limit")
    private Long limit;

    /**
     * 任务类型
     */
    @TableField(value = "type")
    private TaskType type;

    /**
     * 任务开始时间
     */
    @TableField(value = "create_time")
    private Date createTime;

    /**
     * 任务完成时间
     */
    @TableField(value = "complete_time")
    private Date completeTime;

    /**
     * 是否超时
     */
    @TableField(value = "overtime")
    private Boolean overtime;

    /**
     * 是否为售后任务
     */
    @TableField(value = "after_sale")
    private Boolean afterSale;

    /**
     * 任务状态
     */
    @TableField(value = "state")
    private TaskState state;

    /**
     * 是否拒收
     */
    @TableField(value = "reject")
    private Boolean reject;

    /**
     * 任务备注
     */
    @TableField(value = "comment")
    private String comment;

    @Serial
    @TableField(exist = false)
    private static final long serialVersionUID = 1L;

    public Task(Long receiverId, Long phoneId, TaskType type, Long limit, Task lastTask) {
        this.receiverId = receiverId;
        this.phoneId = phoneId;
        this.type = type;
        this.limit = limit;
        if (lastTask != null) {
            this.lastTaskId = lastTask.getId();
            this.teamId = lastTask.getTeamId();
            this.afterSale = lastTask.getAfterSale();
        }
    }
}